<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .box {
      width: 100px;
      height: 100px;
    }

    .box1 {
      background: rebeccapurple;
      margin-bottom: 50px;
      border: 1px solid red;
    }

    .box2 {
      background: blue;
      margin-top: 50px;
      border: 1px solid red;
      float: left; /* 解决margin合并问题 */
    }
  </style>
</head>

<body>
  <div class="box box1">11</div>
  <div class="box box2">22</div>
</body>

</html>
<!-- 
margin合并：上面兄弟元素的下外边距和下面兄弟元素的上外边距会合井，取一个最大的值，而不是相加

无需解决，只给一个上下外边距即可

-->